﻿using System;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.SessionState;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using Castle.Core.Resource;
using System.Web.Routing;

namespace $UIProjectName$
{
    public class Global : System.Web.HttpApplication
    {
        private static WindsorContainer _container;
        
        public static IWindsorContainer Container
        {
            get { return _container; }
        }

        protected void Application_Start(object sender, EventArgs e)
        {
            InitializeWindsor();
            RegisterRoutes(RouteTable.Routes);
        }

        private void InitializeWindsor()
        {
            _container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
            ControllerBuilder.Current.SetControllerFactory(new MvcContrib.Castle.WindsorControllerFactory(_container));
        }

        private void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
        }
    }
}